﻿@model IEnumerable<Testicide.Models.Project>

@{
    ViewBag.Title = "Projects";
}
    <div class="order" id="proOrder">
        <table class="table table-hover">
            <tr>
                <th>
                    Project<a id="openDialog" href="@Url.Action("AddEditRecord", "Project")">
                    <img id=" add" style="width:25px; height:25px;margin-left:20px;" src="~/pictures/addnew.png" /></a>
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Url)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Date)
                </th>
                <th>
                    @using (Html.BeginForm("Search", "Project"))
                    {
                        <input id="searchtxt" name="searchtxt" type="text" />
                        <button id="searchbtn" style="background-color:white; border:none; height:20px; width:20px;"><img id="search" style="width:20px; height:20px;" src="~/pictures/search.png" /></button>
                    }
                </th>
            </tr>

            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        <a id="projectDetails_@item.ID" href="@Url.Action("Index","Module", new { id=item.ID })">
                            @Html.DisplayFor(modelItem => item.Name)
                        </a>
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Url)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Date)
                    </td>
                    <td>
                        <a class="editDialog" id="editProject_@item.ID" href="@Url.Action("AddEditRecord", "Project", new { id = item.ID })">
                            <img class="icons" src="~/pictures/edit.png" />
                        </a> |
                        <a class="confirmDialog" id="deleteProject_@item.ID" href="@Url.Action("DeleteRecord", "Project", new { id = item.ID })">
                            <img class="icons" src="~/pictures/delete.png" />
                        </a> 
                    </td>
                </tr>
            }


        </table>
    </div>
    <div id="dialog-confirm" style="display: none">
        <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
            Are you sure to delete this Project with all its Modules, Features and Scenarios ?
        </p>
    </div>
    <div id="dialog-edit" style="display: none">

    </div>
    <div id="dialog-view" style="display: none">

    </div>    


@section Scripts
{
 <script type="text/javascript">
     $(document).ready(function () {
         $.ajaxSetup({ cache: false });
         $("#openDialog").click(function (e) {
             e.preventDefault();
             var url = $(this).attr('href');
             $("#dialog-edit").dialog({
                 title: 'Create Project',
                 autoOpen: false,
                 resizable: false,
                 height: 355,
                 width: 400,
                 show: { effect: 'drop', direction: "up" },
                 modal: true,
                 draggable: true,
                 open: function (event, ui) {
                     $(this).load(url);
                 },
                 close: function (event, ui) {
                     $(this).dialog('close');
                     location.reload(true);
                 }
             });

             $("#dialog-edit").dialog('open');
             return false;
         });

         $(".editDialog").click(function (e) {
             var url = $(this).attr('href');
             $("#dialog-edit").dialog({
                 title: 'Edit Project',
                 autoOpen: false,
                 resizable: false,
                 height: 355,
                 width: 400,
                 show: { effect: 'drop', direction: "up" },
                 modal: true,
                 draggable: true,
                 open: function (event, ui) {
                     $(this).load(url);
                 },
                 close: function (event, ui) {
                     $(this).dialog('close');
                     location.reload(true);
                 }
             });
             $("#dialog-edit").dialog('open');
             return false;
         });

         $(".confirmDialog").click(function (e) {
             var url = $(this).attr('href');
             $("#dialog-confirm").dialog({
                 autoOpen: false,
                 resizable: false,
                 height: 200,
                 width: 350,
                 show: { effect: 'drop', direction: "up" },
                 modal: true,
                 draggable: true,
                 buttons: {
                     "OK": function () {
                         $(this).dialog("close");
                         window.location = url;
                     },
                     "Cancel": function () {
                         $(this).dialog("close");
                     }
                 }
             });
             $("#dialog-confirm").dialog('open');
             return false;
         });
     });

     function closedialog() {
         $("#dialog-edit").dialog("close");
     }

     $(document).ready(function () {
        $('#searchtxt').autocomplete({
            source: '@Url.Action("AutoComplete")'
        });
    })
    </script>

}